from django.contrib.auth.models import Group, Permission
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serializers.groups import GroupsSerializer
from meiduo_admin.utils import PageNum
from meiduo_admin.serializers.permission import PermissionSerializer


class GroupsView(ModelViewSet):
    # 指定序列化器
    serializer_class = GroupsSerializer
    # 指定数据查询集的对象
    queryset = Group.objects.all()
    # 指定特权管理
    permission_classes = [IsAdminUser]
    # 分页管理
    pagination_class = PageNum

    # 获取权限
    def simple(self,request):
        # 1.获取权限表数据
        data = Permission.objects.all()
        # 2.序列化返回数据
        ser = PermissionSerializer(data,many=True)
        return Response(ser.data)